layui.use(['table', 'admin', 'ax','laydate'], function () {
    var $ = layui.$;
    var table = layui.table;
    var $ax = layui.ax;
    var admin = layui.admin;
    var laydate = layui.laydate;

    laydate.render({
      elem: '#startTime'
        	,value:new Date()
    });

    laydate.render({
      elem: '#endTime'
        	,value:new Date()
    });

    /**
     * 货运订单表管理
     */
    var OrderTransport = {
        tableId: "orderTransportTable"
    };

    /**
     * 初始化表格的列
     */
    OrderTransport.initColumn = function () {
        return [[
            {type: 'checkbox'},
            {field: 'xmmc', sort: true, title: '项目名称'},
            {field: 'xmxz', sort: true, title: '项目性质'},
            {field: 'dycs', sort: true, title: '订单导入次数'},
            {field: 'dyqsr', sort: true, title: '订单导入缺失日'},
            {field: 'ypsz', sort: true, title: '订单已配送至'},
            {field: 'drdds', sort: true, title: '导入订单数'},
            {field: 'ypcdd', sort: true, title: '已派车订单'},
            {field: 'psl', sort: true, title: '配送率',
            	templet: function(d){
            		return (d.ypcdd / d.drdds *100).toFixed(2) + '%'
            	}
			},
            {field: 'drpc', sort: true, title: '当日派车'},
            {field: 'drgl', sort: true, title: '概率',
            	templet: function(d){
            		return (d.drpc / d.ypcdd *100).toFixed(2) + '%'
            	}
			},
            {field: 'crpc', sort: true, title: '次日派车'},
            {field: 'crgl', sort: true, title: '概率',
            	templet: function(d){
            		return (d.crpc / d.ypcdd *100).toFixed(2) + '%'
            	}
			},
            {field: 'grpc', sort: true, title: '隔日派车'},
            {field: 'grgl', sort: true, title: '概率',
            	templet: function(d){
            		return (d.grgl / d.ypcdd *100).toFixed(2) + '%'
            	}
			},
            {field: 'qtpc', sort: true, title: '其他'},
            {field: 'qtgl', sort: true, title: '概率',
            	templet: function(d){
            		return (d.qtpc / d.ypcdd *100).toFixed(2) + '%'
            	}
			},
            {field: 'ywjdd', sort: true, title: '已完结订单'},
            {field: 'ddwjl', sort: true, title: '订单完结率',
            	templet: function(d){
            		return (d.ywjdd / d.ypcdd *100).toFixed(2) + '%'
            	}
			},
            {field: 'sjcydds', sort: true, title: '司机参与订单数'},
            {field: 'sjcyl', sort: true, title: '司机参与率',
            	templet: function(d){
            		return (d.sjcydds / d.ypcdd *100).toFixed(2) + '%'
            	}
			},
            {field: 'chfl', sort: true, title: '存货分类'},
            {field: 'mzl', sort: true, title: '满载率'},
            {field: 'yccs', sort: true, title: '异常车次'},
            {field: 'ywjdd', sort: true, title: '执行完整订单数'},
            {field: 'wal', sort: true, title: '完整率',
            	templet: function(d){
            		return (d.ywjdd / d.ypcdd *100).toFixed(2) + '%'
            	}
			},
        ]];
    };

    /**
     * 点击查询按钮
     */
    OrderTransport.search = function () {
        var queryData = {};
        queryData['startTime'] = $("#startTime").val();
        queryData['endTime'] = $("#endTime").val();
        queryData['operateId'] = $("#operateId").val();
        table.reload(OrderTransport.tableId, {
            where: queryData, page: {curr: 1},
             done:function () {
            }
        });
    };

    /**
     * 导出excel按钮
     */
    OrderTransport.exportExcel = function () {
        var checkRows = table.checkStatus(OrderTransport.tableId);
        if (checkRows.data.length === 0) {
            Feng.error("请选择要导出的数据");
        } else {
            table.exportFile(tableResult.config.id, checkRows.data, 'xls');
        }
    };

    // 渲染表格
    var tableResult = table.render({
        elem: '#' + OrderTransport.tableId,
        url: Feng.ctxPath + '/orderTransport/tmsAnalysislist',
        page: true,
        limit: 40,
        height: "full-60",
        cellMinWidth: 100,
        toolbar: '#toolbarDemo', //开启头部工具栏，并为其绑定左侧模板
        defaultToolbar: ['filter', 'exports', 'print'],
        cols: OrderTransport.initColumn()
    });

    // 搜索按钮点击事件
    $('#btnSearch').click(function () {
        OrderTransport.search();
    });

    // 导出excel
    $('#btnExp').click(function () {
        OrderTransport.exportExcel();
    });
    
    
});
